<template>
  <div>
        <component :is="keyType" :data="data" :keyType="keyType"></component>
  </div>
</template>

<script>
import list from '@/components/key/listPage'
import set from '@/components/key/setPage'
import string from '@/components/key/stringPage'
import zset from '@/components/key/zsetPage'
import hash from '@/components/key/hashPage'
import none from '@/components/key/nonePage'
import server from './server'
export default {
    components:{
        list,set,string,zset,hash,none,server
    },
    data(){
        return {
            keyType:"",
            data:{}
        }
    },
    props:["initParam"],
    created(){
        this.init()
        this.$eventBus.$on('reloadKeyWindow',(data)=>{
            if(data.client!==this.initParam.redisClient){
                return false;
            }
            this.initParam.type="openKey"
        })
    },
    methods:{
        init(){
            if(this.initParam.type==="addKey"){
                this.keyType=this.initParam.keyType
                this.data=this.initParam
            }else if(this.initParam.type==="openKey"){
                this.initParam.redisClient.type(this.initParam.key).then((res)=>{
                    this.keyType=res
                    this.data=this.initParam
                }).catch((e)=>{
                    this.$message.error({
                        message:e.message
                    })
                })
            }else{
                this.keyType=this.initParam.type
                this.data=this.initParam
            }
        }
    },
    watch:{
        initParam(newValue,oldValue){
            this.init()
        }
    }
}
</script>